home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / OUTPORT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  2.0 KB  |  62 lines

  1. /* outport.c --- p 523 */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #define EGA_RAM ((unsigned char far *)0xA0000000)
  5. #define MAX_GR_COLS 640
  6. #define MAX_GR_ROWS 350
  7. #define MAX_COL_BYTES (MAX_GR_COLS/8)
  8. #define BIOS_VIDEO 0x10
  9. #define SETMODE    0            /* BIOS service: set video mode*/
  10. #define EGAMODE    16           /* EGA mode for high resolution*/
  11. #define EGA_GR12 0x3ce          /* Port to select register */
  12. #define EGA_GR_MODE 0x5         /* Register no. for write mode*/
  13.                     /* The box size and the color */
  14. #define XSTART  120
  15. #define YSTART  120
  16. #define XSIZE   280
  17. #define YSIZE   200
  18. #define COLOR   2
  19. static union REGS xr, yr;
  20. static char far *videoram;
  21. main()
  22. {
  23.     int ynum, bytecount, startadrs, startbyte, stopbyte,
  24.         horbytes, skipbytes;
  25.     unsigned temp, egacommand;
  26.             /* Use BIOS to put EGA in high_res graphics mode */
  27.     xr.h.ah = SETMODE;
  28.     xr.h.al = EGAMODE;
  29.     int86 (BIOS_VIDEO, &xr, &yr);
  30.                     /* compute starting address */
  31.     startbyte = XSTART/8;
  32.     startadrs = 80*YSTART + startbyte;
  33.     videoram = EGA_RAM + startadrs;
  34.     skipbytes = MAX_COL_BYTES;
  35.             /* Put EGA in write mode 2. Use outpw. The following
  36.              * code is equivalent to 2 lines:
  37.              *           outportb (EGA_GR12, EGA_GR_MODE);
  38.              *           outportb (EGA_GR_PORT, 2); */
  39.     egacommand = (2<<8) : EGA_GR_MODE;
  40.     outport(EGA_GR12, egacommand);
  41.     stopbyte = (XSTART + XSIZE - 1)/8;
  42.     horbytes = stopbyte - startbyte;
  43.     skipbytes = MAX_COL_BYTES - horbytes;
  44.         /* We already have the proper graphics mode settings */
  45.     for (ynum = 0; ynum < YSIZE; ynum++)
  46.     {
  47.         for (bytecount = 0; bytecount < horbytes; bytecount++)
  48.         {
  49.                     /* Fill in 8 bits at a time.
  50.                      * First read to latch in bytes. */
  51.             temp = *videoram;
  52.             /* Now write out pixel value to all 8 bits at once */
  53.             *videoarm = COLOR;
  54.             videoram++;
  55.         }
  56.                         /* Skip to next row */
  57.         videoram += skipbytes;
  58.     }
  59.         /* Reset graphics environment back to BIOS standard */
  60.     egacommand = EGA_GR_MODE;
  61.     outport(EGA_GR12, egacommand);
  62. }